package com.xuezhixin.example.web.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xuezhixin.core.util.StringUtils;
import com.xuezhixin.example.web.model.Book;
import com.xuezhixin.example.web.service.BookService;

@Controller
@RequestMapping("/book")
public class BookController {

	
	@Resource
	BookService bookService;
	
	@RequestMapping("/list")
	public String list(Book book,Model model){
		List<Book> bookList=bookService.selectList();
		
		//List<Book> bookList=bookService.selectByModel(book);
		model.addAttribute("bookList", bookList);
		return "book/book_list";
	}
	
	
	@RequestMapping("/toAdd")
	public String toAdd(Book book){
		
		return "book/book_toAdd";
	}
	
	@RequestMapping("/add")
	public String add(Book book){
		
		
		book.setBookId(StringUtils.uniqueKey());
		bookService.insert(book);
		
		return "redirect:/rest/book/list";
	}
		
	
	
	@RequestMapping("/delete")
	public String delete(Book book){
		
		bookService.delete(book);
		
		return "redirect:/rest/book/list";
		
	}
	
	
}
